#!/bin/bash
#
#This file is part of CrashRecovery.
#
#    CrashRecovery is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    CrashRecovery is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with CrashRecovery.  If not, see <http://www.gnu.org/licenses/>.
#
#Check for root user -
#Vital for installing programs
uidcheck() {
    owner=${owner:-$(/usr/bin/id -u)}
    if [ "$owner" != "0" ]; then
        err 'Must be root'
        exit 1
    fi
}
echo "Welcome, root."
#VARIABLES

#Coloring

txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
txtrst='\e[0;38m' # Reset

bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White

unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White

#Choice of installing Adobe Flash Player
read -p 'Do you have Adobe Flash Player installed? [y/N]' answer
case "${answer}" in
    [yY]|[yY][eE][sS])
        echo "Moving on...";;
    [nN]|[nN][oO])
#Downloading flash player tarball
	wget http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.378/install_flash_player_11_linux.x86_64.tar.gz : /root
#Untarring the tarball
	tar -xzvf /root/install_flash_player_11_linux.x86_64.tar.gz
#Moving a vital file to the mozilla plugins folder
#(must be done in order for iceweasel to use it)
	mv libflashplayer.so /usr/lib/mozilla/plugins/ ;;
esac

#Choice of installing Java
read -p 'Do you have Java installed? [y/N]' answer
case "${answer}" in
    [yY]|[yY][eE][sS])
        echo "Moving on...";;
    [nN]|[nN][oO])
#Downloading Oracle's Java JDK 7 Tarball
	wget http://download.oracle.com/otn-pub/java/jdk/7u60-b19/jdk-7u60-linux-x64.tar.gz?AuthParam=1404679865_79b05b4b4da3a9727c5da4736f10e384
#Unpacking the Tarball
	tar -xzvf /root/jdk-7u60-linux-x64.tar.gz
#Copying and pasting the jdk folder/directory to /opt/	
	cp -r ~/jdk1.7.0_60 /opt/
#Changing the directory to update
	cd /opt/jdk1.7.0_60
#Updating java and adding it to the mozilla plugins
	update-alternatives --install /usr/bin/java java /opt/jdk1.7.0_60/bin/java 1
	update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_60/bin/javac 1
	update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.7.0_60/jre/lib/amd64/libnpjp2.so 1
	update-alternatives --set java /opt/jdk1.7.0_60/bin/java
	update-alternatives --set javac /opt/jdk1.7.0_60/bin/javac
	update-alternatives --set mozilla-javaplugin.so /opt/jdk1.7.0_60/jre/lib/amd64/libnpjp2.so ;;
esac

#Add-apt repository is originally missing from Kali - this
#will create the command and place it in /usr/sbin
read -p 'Do you want to create the add-apt repository command to easily add PPAs to your sources list? [y/N]' answer
    case "${answer}" in
        [yY]|[yY][eE][sS])
#Necessary for running the PPA Code
	apt-get install python-software-properties
	echo "This might take a while..."
	apt-get install apt-file
	apt-file update
	apt-file search add-apt-repository
#Creating the file "add-apt-repository" in
#/usr/sbin/
	touch /usr/sbin/add-apt-repository
#Placing the code for adding the commands into a file
#called "add-apt-repository" in /usr/sbin/
	cat "PPA Code" > /usr/sbin/add-apt-repository
#File Permission are very important!
#Without these, using the command would not work.
	chmod o+x /usr/sbin/add-apt-repository
	chown root:root /usr/sbin/add-apt-repository
#Some time to rest =)
	sleep 2
#Tell them what happened!
	echo "You are now able to use the command 'add-apt-repository' on your linux machine!";;
#No Option =)
	[nN]|[nN][oO])
	echo "Moving on...";;
    esac

#It's nice to have NetworkManager handle your wifi interfaces =)
read -p 'Do you want NetworkManager to handle your wireless interfaces? [y/N]' answer
case "${answer}" in
    [yY]|[yY][eE][sS])
#Removing the config file
	rm /etc/NetworkManager/NetworkManager.conf
#Adding the config file again
	touch /etc/NetworkManager/NetworkManager.conf
#Replacing the NetworkManager file with config file
	echo NetworkManager > /etc/NetworkManager/NetworkManager.conf;;
    [nN]|[nN][oO])
	echo Skipping;;
esac

#Important in installing any future programs! 
#Faulty sources lists can be a big problem.
read -p 'Do you want to fix your default sources.list? [y/N]' answer
case "${answer}" in
    [yY]|[yY][eE][sS])
#Removing the list file
	rm /etc/apt/sources.list
#Adding the config file again
	touch /etc/apt/sources.list
#Replacing the file with downloaded file
	echo KaliSourcesList > /etc/apt/sources.list;;
    [nN]|[nN][oO])
	echo Skipping;;
esac

#Kali why =/ Well, glad here's an option!
echo "Kali Linux lacks a proper GUI archive manager."
echo "As a result, you have the option of"
echo "installing an archive manager."

#Do you want an archive manager because Kali doesn't have one.
read -p 'Do you want to install the Archive Manager (File Roller)? [y/N]' answer
case "${answer}" in
    [yY]|[yY][eE][sS])
apt-get install unrar unace rar unrar p7zip zip unzip p7zip-full p7zip-rar file-roller -y ;;
	[nN]|[nN][oO])
echo "Skipping...";;
esac

#Adding a non-root user because running as root the whole
#time is not safe for the computer! Viruses, accidental 
#deletions, etc. A single non-root user is nice!
read -p 'Do you want to add a non-root user? [y/N]' answer
case "${answer}" in
    [yY]|[yY][eE][sS])
	echo -e "What will the username be?"
	read user
	adduser $user;;
    [nN]|[nN][oO])
	echo "Skipping";;
esac

#Install ToR
#Learn more about ToR at https://www.torproject.org/
#Tor is free software and an open network that helps you defend against traffic analysis, 
#a form of network surveillance that threatens personal freedom and privacy, 
#confidential business activities and relationships, and state security.
echo -e "\e[0;32m[RECOMMENDED]\e[0;38m Do you want to install ToR for safe browsing? [y/N]"
read answer
case ${answer} in
    [yY]|[yY][eE][sS])
#Installing ToR	
	apt-get install tor
#Starting the Tor service	
	service tor start;;
	[nN]|[nN][oO])
#TOR = DENIED =( Skipping...	
	echo "Skipping...";;
esac

#Automatic Login Option
read -p "Do you want to login automatically as a user/root? [y/N]" answer
case ${answer} in
    [yY]|[yY][eE][sS])
echo -e "Type the name of the \e[1;34m user\e[0;38m. Ex. root, bob, etc."
read USER
#Replacing strings
	sed -i "/AutomaticLogin = root/c\AutomaticLogin = $USER" /etc/gdm3/daemon.conf
	sed -i "/AutomaticLoginEnable = true/c\AutomaticLoginEnable = true" /etc/gdm3/daemon.conf;;
	[nN]|[nN][oO])	
	echo "Skipping...";;

esac

#Lastly Reboot!
read -p "Do you want to Reboot in order to observe changes? [y/N]" answer
case ${answer} in
    [yY]|[yY][eE][sS])
	reboot;;
	[nN]|[nN][oO])	
	echo;;
esac
echo -e "\e[1;32m =========================================="
echo -e "\e[0;37m	Thank 			For	    "
echo -e "\e[1;38m		CrashRecovery		    "
echo -e "\e[0;37m	You	      		Using	    "
echo -e "\e[1;32m =========================================="
sleep 3
echo -e $txtrst
exit